package com.system.registrationPool.service.impl;

import com.system.registrationPool.bean.RegistrationPool;
import com.system.registrationPool.bean.RegistrationPoolList;
import com.system.registrationPool.repository.RegistrationPoolRepository;
import com.system.registrationPool.repository.RegistrationPoolRepository;
import com.system.registrationPool.service.RegistrationPoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
/**
 * @author 林
 */
@Service
public class RegistrationPoolServiceImpl implements RegistrationPoolService {
    @Autowired
    private RegistrationPoolRepository registrationPoolRepository;
    @Override
    public Integer saveRegistrationPool(RegistrationPool registrationPool) {
        RegistrationPool obj =  registrationPoolRepository.save(registrationPool);
        return obj.getPoolId();
    }

    @Override
    public boolean removeRegistrationPoolById(int id) {
        if (registrationPoolRepository.existsById(id)) {
            registrationPoolRepository.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean modifyRegistrationPool(RegistrationPool registrationPool) {
        RegistrationPool obj = registrationPoolRepository.save(registrationPool);
        if(obj != null){
            return true;
        }
        return false;
    }

    @Override
    public RegistrationPool getRegistrationPoolById(int id) {
        if (registrationPoolRepository.existsById(id)) {
            return registrationPoolRepository.getReferenceById(id);
        }
        return null;
    }

    @Override
    public List<RegistrationPool> listAllRegistrationPools() {
        return registrationPoolRepository.findAll();
    }

    @Override
    public List<RegistrationPool> findAllByBusinessIdAndPoolDt(int businessId, LocalDate poolDt) {
        return registrationPoolRepository.findAllByBusinessIdAndPoolDt(businessId,poolDt);
    }
}
